package tp.pr4.items;

import tp.pr4.NavigationModule;
import tp.pr4.RobotEngine;

/**
 * An item that represents fuel. This item can be used at least once and it 
 * provides power energy to the robot. When the item is used the configured 
 * number of times, then it must be removed from the robot inventory
 * @author Alvaro Saez Hernando
 * @author Noel Clemente Montero 
 */
public class Fuel extends Item {
	
	private int power;
	private int times;
	
	/**
	 * Fuel constructor
	 * @param id Item id
	 * @param description Item description
	 * @param power The amount of power energy that this item provides the robot
	 * @param times Number of times the robot can use the item
	 */
	public Fuel(String id,String description,int power,int times){
		super(id,description);
		this.power = power;
		this.times = times;
	}
	
	/**
	 * Fuel can be used as many times as it was configured
	 * @return true it the item still can be used
	 */
	public boolean canBeUsed(){
		if(times>0){
			return true;
		}
		else return false;
	}
	
	/**
	 * Using the fuel provides energy to the robot (if it can be used)
	 * @param r robot that is going to use the fuel
	 * @param nav place where the fuel is going to be used
	 * @return true if the fuel has been used
	 */
	public boolean use(RobotEngine r, NavigationModule nav){	
		boolean used = false;
		if(canBeUsed()){
			r.addFuel(this.power);
			this.times--;
			used = true;
			r.printRobotState();
		}
		return used;
	}
	
	/**
	 * Generates a String with the Item description
	 */
	public String toString(){
		return super.toString()+ "// power = " + this.power + ", times = " + this.times; 
	}
	

}
